package com.copa.l2389;

import java.util.Arrays;

/**
 * @author copa
 * @createDate 2023-03-17 11:57
 * @function 排序+暴力法
 */
public class Test1 {

    public int[] answerQueries(int[] nums, int[] queries) {
        Arrays.sort(nums);
        int n = queries.length;
        int[] result = new int[n];
        int temp;
        for (int i = 0; i < n; i++) {
            temp = 0;
            for (int num : nums) {
                temp += num;
                if (temp > queries[i]) {
                    break;
                }
                result[i]++;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {4,5,2,1};
        int[] queries = {3,10,21};
        int[] result = new Test1().answerQueries(nums, queries);
        for (int i : result) {
            System.out.print(i + "\t");
        }
    }
}
